package me.ezitku.base.File

/**
 * Created by yurqi on 2017/6/3.
 */


fun intToByteArray(i: Int): ByteArray {
    val result = ByteArray(4)
    result[0] = (i shr 24 and 0xFF).toByte()
    result[1] = (i shr 16 and 0xFF).toByte()
    result[2] = (i shr 8 and 0xFF).toByte()
    result[3] = (i and 0xFF).toByte()
    return result
}


fun byteArrayToInt(bytes: ByteArray): Int {
    var value = 0
    for (i in 0..3) {
        val shift = (4 - 1 - i) * 8
        value += bytes[i].toInt() and 0x000000FF shl shift//往高位游
    }
    return value
}

val Int.toByteArray: ByteArray
    get() = intToByteArray(this)